﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Security;

namespace Company.Web.Infrastructure
{
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public sealed class ValidateStringLengthAttribute : ValidationAttribute
    {
        private const string Message = "'{0}' no puede tener menos de {1} caracteres.";
        private readonly int m_MinCHaracters = 5;

        public ValidateStringLengthAttribute(int MinOfCharacters): base(Message)
        {
            m_MinCHaracters = MinOfCharacters;
        }

        public override string FormatErrorMessage(string name)
        {
            return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString, name, m_MinCHaracters);
        }

        public override bool IsValid(object value)
        {
            string m_valueAsString = value as string;
            return (m_valueAsString != null && (m_valueAsString.Length >= m_MinCHaracters));
        }
    }
}
